<?php

class Core_Model_DbTable_Category_Systems extends Core_Model_DbTable_Category_Abstract
{
	const TABLE_NAME                = 'system_categories';
	protected $_name				= self::TABLE_NAME;
    protected $_rowClass            = 'Core_Model_Category_System';
	
	static $_instance = null;
	
	/**
	 *
	 * @return Core_Model_DbTable_Category_Systems 
	 */
	public static function getInstance()
	{
		if( !(self::$_instance instanceof Core_Model_DbTable_Category_Systems) )
		{
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	public static function getArrCategories($id_parent = NULL)
	{
		$arrCategories = array();
		$listCategories = self::getInstance()->getListCategories($id_parent);
		foreach($listCategories as $category)
		{
			/*@var $category Core_Model_Category*/
			$arrCategories[$category->id] =  str_replace('&amp;', '&', $category->name);
		}		
		return $arrCategories;
	}
	
	public function getListCategories($id_parent = NULL)
	{
		$select = $this->select();
		if( $id_parent !==  NULL)
		{
			$select->where('id_parent = ?', $id_parent);
		}
		else
		{
			$select->where('id_parent IS NULL');
		}
		return $this->fetchAll($select);
	}
}